<?php
require_once '../sub/init.php';
header("Cache-control: private");
require_once 'chkUadm.php';
require_once ZEAI.'cache/config_adm.php';
if($t == 'crm'){
	if(!in_array('crm_left_top_menu',$QXARR) && !in_array('crm',$QXARR))exit(noauth());
	$left_top_menu = dataIO($_ADM['crm_left_top_menu'.$session_uid],'out');
}else{
	if(!in_array('adm_left_top_menu',$QXARR) && !in_array('crm',$QXARR))exit(noauth());
	$left_top_menu = dataIO($_ADM['adm_left_top_menu'.$session_uid],'out');
}
$left_top_menuARR = explode(',',$left_top_menu );?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link href="css/main.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css">
<script src="<?php echo HOST;?>/res/www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="js/Sortable1.6.1.js"></script>
<style>
.rolebox{font-size:14px}
.rolebox dt{margin:15px 0 5px 0;font-weight:bold;text-align:left}
.rolebox dd{width:100%}
.rolebox dd li{width:20%;line-height:30px;float:left}
.tiaose{font-weight:bold}
#left_diy_box{margin:20px}
.ltbl{margin-top:25px;margin-left:20px;width:999px}
.stepbox{margin-bottom:20px}
.stepbox .stepli{font-size:14px;margin-top:5px}
.stepbox .stepli li{min-width:110px;padding:5px 10px;float:left;margin:5px;border:#ddd 1px solid;cursor:move;background-color:#f8f8f8;border-radius:3px}
</style>
</head>
<body class="body">
<form id="ZEAIFORM">
<table border="0" cellpadding="10" cellspacing="1" bgcolor="#eeeeee"  class="ltbl">
<tr>
<td width="150" height="60" align="center" bgcolor="#FFFFFF"><div class="S18 B">快捷入口菜单</div><div class="S12 C999">按住不放上下拖动调序</div></td>
<td rowspan="2" align="center" valign="top" bgcolor="#FFFFFF"><div id="left_diy_box"></div>
</td>
</tr>
<tr>
<td align="center" valign="top" bgcolor="#FFFFFF">
<div id="left_diy_menu" class="stepbox">
	<div class="stepli" id="stepli">
	<?php
    if (count($left_top_menuARR) >= 1 && is_array($left_top_menuARR) && !empty($left_top_menu)){
        foreach ($left_top_menuARR as $V) {
			$VARR = explode('|WWW.A9A.CN|',$V);
			$url=$VARR[0];$title=$VARR[1];
			echo '<li title="按住不放上下拖动调序"><a url="'.$url.'">'.$title.'</a></li>';
		}
    }?>
	</div>
    <div class="clear"></div>
</div>
</td>
</tr>
</table>
<input name="submitok" type="hidden" value="<?php echo ($t == 'crm')?'crm_left_top_menu':'adm_left_top_menu';?>">
<input name="left_top_menu" id="left_top_menu" type="hidden" value="">
<input name="uu" id="uu" type="hidden" value="<?php echo $session_uid;?>">
<input name="pp" id="pp" type="hidden" value="<?php echo $session_pwd;?>">
</form>
<div class="savebtnbox"><button type="button" class="btn size3" id="save">确定并保存</button></div>
<script>
save.onclick = function(){
	var DATAPX=[],left_DATA=''
	zeai.listEach(zeai.tag(stepli,'a'),function(a){
		var url=a.getAttribute("url"),title=a.innerHTML;
		DATAPX.push(url+'|WWW.A9A.CN|'+title);
		left_DATA += '<a url="'+url+'">'+title+'</a>';
	});
	left_top_menu.value=DATAPX.join(",");
	zeai.ajax({url:'<?php echo HOST;?>/sub/cache'+zeai.extname,form:ZEAIFORM},function(e){var rs=zeai.jsoneval(e);
		zeai.msg(rs.msg);
		if(rs.flag==1){
			parent.diydd.html(left_DATA);
			setTimeout(function(){parent.location.reload(true);},1000);
		}
	});
}
zeai.listEach(zeai.tag(parent.leftMain,'dt'),function(obj,n){
	if(n>0){
		var T=obj.innerHTML,html='';
		T  = T.replace(/<i.*?>.*?<\/i[^>]*>/ig,"");
		LI = obj.nextElementSibling;//F = obj.nextElementSibling.innerHTML;
		html  = '<div class="rolebox">'+
		'    <dt>'+T+'</dt>'+
		'    <dd>';
		zeai.listEach(zeai.tag(LI,'a'),function(obj2,n2){
			value=obj2.getAttribute("url");
			title=obj2.innerHTML;
			title= title.replace(/<font.*?>.*?<\/font[^>]*>/ig,"");
			title2=title.replace('●','');
			forid=n+''+n2;
			if(chkhas(value)){
				chked=' checked';
			}else{
				chked='';
			}
			html  += '<li><input type="checkbox" name="list[]" class="checkskin" value="'+value+'|WWW.A9A.CN|'+title+'" id="li'+forid+'" '+chked+'><label for="li'+forid+'" class="checkskin-label" onclick="munuajax(\''+value+'\',\''+title+'\')"><i class="i1"></i><b class="W150">'+title2+'</b></label></li>';
		});
		html  += '<div class="clear"></div>'+
		'    </dd>'+
		'</div>';
		left_diy_box.append(html);
	}
});
function munuajax(value,title) {
	if(chkhas(value)){
		var dom = getdom(value);
		if(typeof(dom) == "object"){
			dom.parentNode.remove();
		}
	}else{
		stepli.append('<li><a url="'+value+'">'+title+'</a></li>');
	}
}
function chkhas(value){
	var f=false;
	zeai.listEach(zeai.tag(stepli,'a'),function(a){
		var url=a.getAttribute("url");
		if(value==url){
			f=true;	
		}
	});
	return f;
}
function getdom(value){
	var dom='';
	zeai.listEach(zeai.tag(stepli,'a'),function(a){
		url=a.getAttribute("url");
		if(value==url)dom=a;
	});
	return dom;
}
function drag_init(){
	(function (){
		[].forEach.call(left_diy_menu.getElementsByClassName('stepli'), function (el){
			Sortable.create(el, {
				group: 'zeai_reg',
				animation:150
			});
		});
	})();
}
drag_init();
</script>
<?php require_once 'bottomadm.php';?>